package com.ueboot.weishop.admin.configure;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800,redisNamespace="weishopadmin")
public class AdminRedisConfig extends CachingConfigurerSupport {
    /**
     * spring cache注解支持。
     * @param redisTemplate
     * @return
     */
    @Bean
    public CacheManager cacheManager(
            @SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {
        RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
        List<String> cacheNames = new ArrayList<String>();
        //定义缓存名称，使用是可以指定名称用于区分不同的缓存数据
        cacheNames.add("default");
        cacheNames.add("systemCache");
        cacheNames.add("springCacheManager");
        cacheNames.add("activity");
        cacheNames.add("activityAttr");
        cacheNames.add("goodsInfo");
        cacheNames.add("provinceCityDealer");
        cacheNames.add("customer");
        cacheNames.add("cusgroup");
        cacheNames.add("oilvin");
        cacheNames.add("orders");
        cacheManager.setCacheNames(cacheNames);
        return cacheManager;
    }

}